Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if message already delivered #23

Merged
merged 13 commits into from
Sep 15, 2023
Merged

Conversation

cam-schultz
Copy link
Collaborator

@cam-schultz cam-schultz commented Aug 31, 2023

Why this should be merged

How this works

  • Adds a call to the TeleporterMessenger contract method messageReceived (https://github.com/ava-labs/teleporter/blob/main/contracts/src/Teleporter/TeleporterMessenger.sol#L492) in MessageManager:ShouldSendMessage. If the message has already been received, return early
  • Moves message delivery decision logic out of DestinationClient and into MessageManager. DestinationClient now only manages interaction with the destination chain via the relayer EOA, while MessageManager manages protocol unpacking and delivery decision logic.

How this was tested

CI, Teleporter integration tests, & manual testing.

Copy link
Contributor

@bernard-avalabs bernard-avalabs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me. I left a question about error handling for the receive message check.

return messageDestinationID == allowedDestinationID
}

func isAllowedRelayer(allowedRelayers []common.Address, eoa common.Address) bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should relayers be destination specific?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the code level, this particular check is ensuring that the relayer EOA that will send the tx to the destination is included in the Teleporter message's list of allowed relayers. The function above checks that the EVM client that will send the tx is sending to the destination chain ID included in the Teleporter message.

At the architectural level, DestinationClient is the entity responsible for sending the tx to the correct destination chain. MessageRelayers should be composed of exactly one DestinationClient, so in that sense, relayers are destination specific.

zap.String("destinationChainID", destinationChainID.String()),
zap.String("teleporterMessageID", teleporterMessage.MessageID.String()),
)
return false, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the caller should look at the err to distinguished between the message has been received and error conditions. Do the callers do that currently? How should the caller handle errors?

Copy link
Collaborator Author

@cam-schultz cam-schultz Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to ShouldSendMessage is valid regardless of the value of the boolean, as long as the error is nil. We perform that check here: https://github.com/ava-labs/awm-relayer/blob/2060ab680cbd1a2501a87ac3ec01d6cd9da79f37/relayer/message_relayer.go#L80-L95

I added a comment to the MessageManager interface noting that the boolean should be ignored if a error is returned.

Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me at a high level. I like the ShouldSendMessage interface a lot. I left a few minor suggestions.

messages/teleporter/message_manager.go Outdated Show resolved Hide resolved
m.logger.Info("Relayer EOA not allowed to deliver this message.")
return false, nil
}
if !isDestination(destinationChainID, destinationClient.DestinationChainID()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check seems redundant given that we look up the destination client by the chain ID already. If we choose to keep it, could we move this to right after the destinationClient is looked up from the destinationClients map?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I've removed it altogether, but left the corresponding method in DestinationClient, as it makes sense as a getter for that interface.

messages/teleporter/message_manager.go Show resolved Hide resolved
Copy link

@minghinmatthewlam minghinmatthewlam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just nits for changing comment and removing isDestination since not used

geoff-vball
geoff-vball previously approved these changes Sep 8, 2023
Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one small comment on something mostly unrelated. The PR looks good to me 👍

messages/teleporter/message_manager.go Show resolved Hide resolved
geoff-vball
geoff-vball previously approved these changes Sep 13, 2023
Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

gwen917
gwen917 previously approved these changes Sep 13, 2023
Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To small nits, but otherwise LGTM

messages/teleporter/message_manager.go Outdated Show resolved Hide resolved
messages/teleporter/message_manager.go Outdated Show resolved Hide resolved
@cam-schultz cam-schultz dismissed stale reviews from gwen917 and geoff-vball via 0a1a368 September 14, 2023 20:11
Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@cam-schultz cam-schultz merged commit c997e81 into main Sep 15, 2023
6 checks passed
@cam-schultz cam-schultz deleted the check-message-already-delivered branch September 15, 2023 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Do not relay messages that have already been delivered
6 participants